package com.baizhi.shane.shane.controller;

import com.baizhi.shane.common.base.Result;
import com.baizhi.shane.constant.ApiMapping;
import com.baizhi.shane.constant.TableNameMapping;
import com.baizhi.shane.shane.entity.ShaneCommentQuestion;
import com.baizhi.shane.shane.entity.ShaneQuestion;
import com.baizhi.shane.shane.service.ShaneCollectQuestionService;
import com.baizhi.shane.shane.service.ShaneCommentQuestionService;
import com.baizhi.shane.shane.service.ShaneLikesQuestionService;
import com.baizhi.shane.shane.service.ShaneQuestionService;
import com.baizhi.shane.shane.vo.*;
import com.baizhi.shane.sys.vo.IdVO;
import com.baizhi.shane.sys.vo.SuccessedOutVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 闻柏智
 * @date 2023/08/20 23:23:50
 */
@RestController
@RequestMapping(TableNameMapping.SHANE_QUESTION)
@Api(tags="问题表")
public class ShaneQuestionController {

    @Resource
    private ShaneQuestionService shaneQuestionService;
    @Resource
    private ShaneLikesQuestionService shaneLikesQuestionService;
    @Resource
    private ShaneCollectQuestionService shaneCollectQuestionService;
    @Resource
    private ShaneCommentQuestionService shaneCommentQuestionService;

    /**
     * 新增一个问题
     *
     * @Author 闻柏智
     * @Date 16:56 2024/3/1
     * @Param questionInsertInVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="新增一个问题", notes="新增一个问题")
    @PostMapping(value = ApiMapping.INSERT_ONE)
    public Result<SuccessedOutVO> insertOne(
            @RequestBody QuestionInsertInVO questionInsertInVO
    ) {
        SuccessedOutVO successedOutVO = shaneQuestionService.insertOne(questionInsertInVO);
        return Result.OK(successedOutVO);
    }

    /**
     * 查询单个问题-原生
     *
     * @Author 闻柏智
     * @Date 22:39 2024/3/3
     * @Param questionId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.entity.ShaneQuestion>
     **/
    @ApiOperation(value="查询单个问题-原生", notes="查询单个问题-原生")
    @GetMapping(value = ApiMapping.GET_ONE_ORIGIN)
    public Result<ShaneQuestion> getOneOrigin(
            @RequestParam("questionId") @ApiParam("问题ID") Long questionId
    ) {
        ShaneQuestion shaneQuestion = shaneQuestionService.getById(questionId);
        return Result.OK(shaneQuestion);
    }

    /**
     * 通过ID编辑问题
     *
     * @Author 闻柏智
     * @Date 22:34 2024/3/3
     * @Param shaneQuestion
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="通过ID编辑问题", notes="通过ID编辑问题")
    @PostMapping(value = ApiMapping.UPDATE_ONE_BY_ID)
    public Result<SuccessedOutVO> updateOneById(
            @RequestBody ShaneQuestion shaneQuestion
    ) {
        SuccessedOutVO successedOutVO = shaneQuestionService.updateOneById(shaneQuestion);
        return Result.OK(successedOutVO);
    }

    /**
     * 通过关键字模糊查询问题列表
     *
     * @Author 闻柏智
     * @Date 15:43 2024/1/22
     * @Param pageInVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.PageQuestionOutVO>
     **/
    @ApiOperation(value="通过关键字模糊查询问题列表", notes="通过关键字模糊查询问题列表")
    @GetMapping(value = ApiMapping.PAGE_BY_CONTENT)
    public Result<PageQuestionOutVO> pageByContent(PageInVO pageInVO) {
        List<PageQuestionOutVO> pageQuestionOutVOList = shaneQuestionService.pageByContent(pageInVO);
        return Result.OK(pageQuestionOutVOList);
    }

    /**
     * 我发布过的问题
     *
     * @Author 闻柏智
     * @Date 21:15 2024/3/3
     * @Param
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.PageQuestionOutVO>
     **/
    @ApiOperation(value="我发布过的问题", notes="我发布过的问题")
    @GetMapping(value = ApiMapping.MY_POSTED)
    public Result<ShaneQuestion> myPosted() {
        List<ShaneQuestion> shaneQuestionList = shaneQuestionService.myPosted();
        return Result.OK(shaneQuestionList);
    }

    /**
     * 我收藏的问题
     *
     * @Author 闻柏智
     * @Date 14:28 2024/3/4
     * @Param
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.entity.ShaneQuestion>
     **/
    @ApiOperation(value="我收藏的问题", notes="我收藏的问题")
    @GetMapping(value = ApiMapping.MY_COLLECTED)
    public Result<ShaneQuestion> myCollected() {
        List<ShaneQuestion> shaneQuestionList = shaneQuestionService.myCollected();
        return Result.OK(shaneQuestionList);
    }

    /**
     * 通过问题ID列表查询这些问题的标签列表
     *
     * @Author 闻柏智
     * @Date 17:21 2024/1/7
     * @Param idListStr
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.QuestionLabelOutVO>
     **/
    @ApiOperation(value="通过问题ID列表查询这些问题的标签列表", notes="通过问题ID列表查询这些问题的标签列表")
    @GetMapping(value = ApiMapping.GET_QUESTION_LABEL_LIST_BY_QUESTION_ID_LIST)
    public Result<List<QuestionLabelOutVO>> getQuestionLabelListByQuestionIdList(@RequestParam("idListStr") @ApiParam("多个id用','分割") String idListStr) {
        List<QuestionLabelOutVO> QuestionLabelOutVOList = shaneQuestionService.getQuestionLabelListByQuestionIdList(idListStr);
        return Result.OK(QuestionLabelOutVOList);
    }

    /**
     * 通过问题ID查询单个问题的标签
     *
     * @Author 闻柏智
     * @Date 17:28 2024/1/7
     * @Param questionId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.QuestionLabelOutVO>
     **/
    @ApiOperation(value="通过问题ID查询单个问题的标签", notes="通过问题ID查询单个问题的标签")
    @GetMapping(value = ApiMapping.GET_QUESTION_LABEL_BY_QUESTION_ID)
    public Result<QuestionLabelOutVO> getQuestionLabelByQuestionId(@RequestParam("questionId") @ApiParam("问题ID") Long questionId) {
        QuestionLabelOutVO QuestionLabelOutVO = shaneQuestionService.getQuestionLabelByQuestionId(questionId);
        return Result.OK(QuestionLabelOutVO);
    }

    /**
     * 用户点赞问题，只需要questionId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 18:32 2023/10/4
     * @Param questionUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户点赞问题", notes="用户点赞问题")
    @PostMapping(value = ApiMapping.INSERT_ONE_QUESTION_LIKES)
    public Result<String> insertOneQuestionLikes(@RequestBody QuestionUserRelVO questionUserRelVO) {

        String succeed = shaneLikesQuestionService.insertOneQuestionLikes(questionUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户取消点赞问题，只需要questionId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 18:48 2023/10/4
     * @Param questionUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户取消点赞问题", notes="用户取消点赞问题")
    @PostMapping(value = ApiMapping.DELETE_ONE_QUESTION_LIKES)
    public Result<String> deleteOneQuestionLikes(@RequestBody QuestionUserRelVO questionUserRelVO) {

        String succeed = shaneLikesQuestionService.deleteOneQuestionLikes(questionUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户收藏问题，只需要questionId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 19:00 2023/10/4
     * @Param questionUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户收藏问题", notes="用户收藏问题")
    @PostMapping(value = ApiMapping.INSERT_ONE_QUESTION_COLLECT)
    public Result<String> insertOneQuestionCollect(@RequestBody QuestionUserRelVO questionUserRelVO) {

        String succeed = shaneCollectQuestionService.insertOneQuestionCollect(questionUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户取消收藏问题，只需要questionId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 19:14 2023/10/4
     * @Param questionUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户取消收藏问题", notes="用户取消收藏问题")
    @PostMapping(value = ApiMapping.DELETE_ONE_QUESTION_COLLECT)
    public Result<String> deleteOneQuestionCollect(@RequestBody QuestionUserRelVO questionUserRelVO) {

        String succeed = shaneCollectQuestionService.deleteOneQuestionCollect(questionUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 获取指定问题下所有的评论
     *
     * @Author 闻柏智
     * @Date 15:27 2024/2/28
     * @Param questionId
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CommentQuestionVO>>
     **/
    @ApiOperation(value="获取指定问题下所有的评论", notes="获取指定问题下所有的评论")
    @GetMapping(value = ApiMapping.GET_ALL_COMMENT_BY_QUESTION_ID)
    public Result<List<CommentQuestionVO>> getAllCommentByQuestionId(@RequestParam Long questionId) {
        List<CommentQuestionVO> commentQuestionVOList = shaneCommentQuestionService.getAllCommentByQuestionId(questionId);
        return Result.OK(commentQuestionVOList);
    }

    /**
     * 新增一个评论
     *
     * @Author 闻柏智
     * @Date 16:20 2024/2/28
     * @Param shaneCommentQuestion
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="新增一个评论", notes="新增一个评论")
    @PostMapping(value = ApiMapping.INSERT_ONE_COMMENT)
    public Result<SuccessedOutVO> insertOneComment(@RequestBody ShaneCommentQuestion shaneCommentQuestion) {
        SuccessedOutVO successedOutVO = shaneCommentQuestionService.insertOneComment(shaneCommentQuestion);
        return Result.OK(successedOutVO);
    }

    /**
     * 删除一个问题-通过ID
     *
     * @Author 闻柏智
     * @Date 18:05 2024/1/1
     * @Param idVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="删除一个问题-通过ID", notes="删除一个问题-通过ID")
    @PostMapping(value = ApiMapping.DELETE_ONE_QUESTION_BY_ID)
    public Result<SuccessedOutVO> deleteOneQuestionById(@RequestBody IdVO idVO) {

        SuccessedOutVO successedOutVO = shaneQuestionService.deleteOneQuestionById(idVO);

        return Result.OK(successedOutVO);
    }

    /**
     * 通过关键字查询问题列表的元素数量和分页个数
     *
     * @Author 闻柏智
     * @Date 20:11 2024/1/1
     * @Param pageInVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountAndPageOutVO>
     **/
    @ApiOperation(value="通过关键字查询问题列表的元素数量和分页个数", notes="通过关键字查询问题列表的元素数量和分页个数")
    @GetMapping(value = ApiMapping.COUNT_AND_PAGE_BY_CONTENT)
    public Result<CountAndPageOutVO> countAndPageByContent(PageInVO pageInVO ) {

        CountAndPageOutVO successedOutVO = shaneQuestionService.countAndPageByContent(pageInVO);

        return Result.OK(successedOutVO);
    }

    /**
     * 通过问题ID列表查询这些问题的点赞数量
     *
     * @Author 闻柏智
     * @Date 22:53 2024/1/17
     * @Param questionIdList
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CountVO>>
     **/
    @ApiOperation(value="通过问题ID列表查询这些问题的点赞数量", notes="通过问题ID列表查询这些问题的点赞数量")
    @PostMapping(value = ApiMapping.GET_QUESTION_LIKE_COUNT_BY_QUESTION_ID_LIST)
    public Result<List<CountVO>> getQuestionLikeCountByQuestionList(@RequestBody List<Long> questionIdList ) {
        List<CountVO> countVOList = this.shaneQuestionService.getQuestionLikeCountByQuestionIdList(questionIdList);
        return Result.OK(countVOList);
    }

    /**
     * 通过问题ID查询单个问题的点赞数量
     *
     * @Author 闻柏智
     * @Date 23:10 2024/1/17
     * @Param questionId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountVO>
     **/
    @ApiOperation(value="通过问题ID查询单个问题的点赞数量", notes="通过问题ID查询单个问题的点赞数量")
    @GetMapping(value = ApiMapping.GET_ONE_QUESTION_LIKE_COUNT_BY_QUESTION_ID)
    public Result<CountVO> getOneQuestionLikeCountByQuestionId(Long questionId ) {
        CountVO countVO = this.shaneQuestionService.getOneQuestionLikeCountByQuestionId(questionId);

        return Result.OK(countVO);
    }

    /**
     * 通过问题ID列表查询这些问题的收藏数量
     *
     * @Author 闻柏智
     * @Date 13:21 2024/1/18
     * @Param questionIdList
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CountVO>>
     **/
    @ApiOperation(value="通过问题ID列表查询这些问题的收藏数量", notes="通过问题ID列表查询这些问题的收藏数量")
    @PostMapping(value = ApiMapping.GET_QUESTION_COLLECT_COUNT_BY_QUESTION_ID_LIST)
    public Result<List<CountVO>> getQuestionCollectCountByQuestionIdList(@RequestBody List<Long> questionIdList ) {
        List<CountVO> countVOList = this.shaneQuestionService.getQuestionCollectCountByQuestionIdList(questionIdList);
        return Result.OK(countVOList);
    }

    /**
     * 通过问题ID查询单个问题的收藏数量
     *
     * @Author 闻柏智
     * @Date 13:25 2024/1/18
     * @Param questionId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountVO>
     **/
    @ApiOperation(value="通过问题ID查询单个问题的收藏数量", notes="通过问题ID查询单个问题的收藏数量")
    @GetMapping(value = ApiMapping.GET_ONE_QUESTION_COLLECT_COUNT_BY_QUESTION_ID)
    public Result<CountVO> getOneQuestionCollectCountByQuestionId(Long questionId ) {
        CountVO countVO = this.shaneQuestionService.getOneQuestionCollectCountByQuestionId(questionId);

        return Result.OK(countVO);
    }

    /**
     * 通过问题ID列表查询这些问题的评论数量
     *
     * @Author 闻柏智
     * @Date 13:30 2024/1/18
     * @Param questionIdList
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CountVO>>
     **/
    @ApiOperation(value="通过问题ID列表查询这些问题的评论数量", notes="通过问题ID列表查询这些问题的评论数量")
    @PostMapping(value = ApiMapping.GET_QUESTION_COMMENT_COUNT_BY_QUESTION_ID_LIST)
    public Result<List<CountVO>> getQuestionCommentCountByQuestionIdList(@RequestBody List<Long> questionIdList ) {
        List<CountVO> countVOList = this.shaneQuestionService.getQuestionCommentCountByQuestionIdList(questionIdList);
        return Result.OK(countVOList);
    }

    /**
     * 通过问题ID查询单个问题的评论数量
     *
     * @Author 闻柏智
     * @Date 13:39 2024/1/18
     * @Param questionId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountVO>
     **/
    @ApiOperation(value="通过问题ID查询单个问题的评论数量", notes="通过问题ID查询单个问题的评论数量")
    @GetMapping(value = ApiMapping.GET_ONE_QUESTION_COMMENT_COUNT_BY_QUESTION_ID)
    public Result<CountVO> getOneQuestionCommentCountByQuestionId(Long questionId ) {
        CountVO countVO = this.shaneQuestionService.getOneQuestionCommentCountByQuestionId(questionId);

        return Result.OK(countVO);
    }


    /**
     * 随机初始化各种关系表的数据，对系统业务毫无意义
     *
     * @Author 闻柏智
     * @Date 23:27 2023/9/29
     * @Param
     * @return com.baizhi.shane.common.base.Result<?>
     **/
    @ApiOperation(value="TEST测试初始化关联表", notes="TEST测试初始化关联表")
    @PostMapping(value = ApiMapping.TEST_INIT_ASSOCIATION_TABLE)
    public Result<?> testInitAssociationTable() {

        shaneQuestionService.testInitAssociationTable();

        return Result.OK();
    }

    /**
     * 通过ID查询单个问题信息
     *
     * @Author 闻柏智
     * @Date 16:07 2024/2/29
     * @Param questionId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.GetOneQuestionOutVO>
     **/
    @ApiOperation(value="通过ID查询单个问题信息", notes="通过ID查询单个问题信息")
    @GetMapping(value = ApiMapping.GET_ONE_QUESTION_BY_ID)
    public Result<GetOneQuestionOutVO> getOneQuestionById(@RequestParam("questionId") @ApiParam("问题ID") Long questionId) {
        GetOneQuestionOutVO getOneQuestionOutVO = this.shaneQuestionService.getOneQuestionById(questionId);

        return Result.OK(getOneQuestionOutVO);
    }





}
